package us.versus.them.b3ge.minigames.cards;

enum Suit {
	Hearts;
	Diamonds;
	Clubs;
	Spades;
}

class Card {
	public var suit:Suit;
	public var value:Int;
	public var used:Bool;

	public function new( ?suit:Suit=null, ?value:Int=0 ) {
		this.suit = suit;
		this.value = value;
		this.used = false;
	}

	public function valueToString( value:Int ) {
		switch( value ) {
			case 1: return 'A';
			case 10: return '0';
			case 11: return 'J';
			case 12: return 'Q';
			case 13: return 'K'; 
		}
		return '' + value;
	}

	public function suitToString( suit:Suit ) {
		switch( suit ) {
			case Hearts:   return 'h';
			case Diamonds: return 'd';
			case Clubs:    return 'c';
			case Spades:   return 's';
		}
	}

	public function toString() {
		return (
			  this.valueToString( this.value ) 
			+ this.suitToString( this.suit ) 
			+ ( if ( this.used ) '!' else ' ' )
		);
	}

	public function valueFromString( str:String ) : Int {
		return 0;
	}

	public function suitFromString( str:String ) : Suit {
		return Hearts;
	}


	public function fromString( str:String ) {
		this.value = this.valueFromString( str.substr( 0 ,1 ) );
		this.suit = this.suitFromString( str.substr( 1, 1 ) );
		return this;
	}

	public static inline function compare( a:Card, b:Card ) : Int {
		return a.value - b.value;
	}

}
